package com.example.home.metro;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.home.R;
import com.example.home.metro.activity.PathImgActivity;
import com.example.home.metro.adapter.PathMessageAdapter;
import com.example.home.metro.bean.PathMessageBean;
import com.example.home.tool.OKHttpTool;

public class MetroMainActivity extends AppCompatActivity {
    private ImageView back;
    private TextView title;
    private ImageView path;
    private TextView stepInfoName;
    private RecyclerView rcvList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_metro_main);
        initView();
        getPathMessage();
    }

    private void getPathMessage() {
        OKHttpTool.doNetRequest("prod-api/api/metro/list?currentName=建国门",
                OKHttpTool.GET,
                PathMessageBean.class,
                new OKHttpTool.NetCallback() {
                    @Override
                    public void onSuccess(Object obj) {
                        PathMessageBean pathMessageBean = (PathMessageBean) obj;
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                bindPathMessage(pathMessageBean);
                            }
                        });
                    }

                    @Override
                    public void onFailure(String msg) {

                    }
                });
    }

    private void bindPathMessage(PathMessageBean pathMessageBean) {
        PathMessageAdapter pathMessageAdapter = new PathMessageAdapter(MetroMainActivity.this,pathMessageBean.getData());
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(MetroMainActivity.this);
        rcvList.setAdapter(pathMessageAdapter);
        rcvList.setLayoutManager(linearLayoutManager);
    }

    private void initView() {

        back = findViewById(R.id.back);
        title = findViewById(R.id.title);
        path = findViewById(R.id.path);
        stepInfoName = findViewById(R.id.stepInfo_name);
        rcvList = findViewById(R.id.rcv_list);

        path.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MetroMainActivity.this, PathImgActivity.class);
                startActivity(intent);
            }
        });
        stepInfoName.setText("建国门");
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MetroMainActivity.this.finish();
            }
        });
    }
}